package com.ssm.controller;

import com.ssm.model.Student;

import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Lenovo on 2019-4-21.
 */
@Controller
@RequestMapping("/Student")
public class StudentController {


    @RequestMapping("list.do")
    public String list(@CookieValue("city")String city){
        System.out.println(city);
        return "listStudents";
    }
    @RequestMapping(value = "toAdd.do")
    public String toAdd(){
          return "addStudent";
    }
    @RequestMapping(value = "add.do",method = RequestMethod.POST)
    public ModelAndView add(Student student, HttpServletResponse res){
        Cookie cookie=new Cookie("city","zhuhai");
        res.addCookie(cookie);
        ModelAndView mv=new ModelAndView();
        mv.addObject("student",student);
        mv.setViewName("redirect:list.do");
        return mv;
    }
}
